﻿
using CMS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class MemberProvider : IProvider<Member>
    {
        private CargoEntities db = new CargoEntities();

        public int Delete(Member t)
        {
            if (t == null) return 0;
            var model = db.Member.ToList().FirstOrDefault(item => item.Id == t.Id);
            if (model != null)
            {
                db.Member.Remove(model);
                return db.SaveChanges();
            }
            return 0;
        }

        public int Insert(Member t)
        {
            if (t == null) return 0;
            db.Member.Add(t);
            return db.SaveChanges();
        }

        public List<Member> Select()
        {
            return db.Member.ToList();
        }

        public int Update(Member t)
        {
            if (t == null) return 0;
            var model = db.Member.ToList().FirstOrDefault(item => item.Id == t.Id);
            if (model != null)
            {
                model.Password = t.Password;
                model.Role = t.Role;
                int count = db.Member.Count();
                return count;
            }
            return 0;
        }
    }
}
